const path = require('path')
// import { CleanWebpackPlugin } from 'clean-webpack-plugin' // node.js 还不支持ES6的import模块导入语法.
const {
  CleanWebpackPlugin
} = require('clean-webpack-plugin')

module.exports = {
  entry: {
    indexName: path.join(__dirname, 'index.js'),
    appFileName: path.join(__dirname, 'app.js')
  },
  output: {
    path: path.join(__dirname, 'dist'),
    // filename: '[name]_[hash].js'
    filename: '[name]_[chunkhash].js'
  },
  mode: 'development',
  module: {
    rules: [{
      test: /\.(png|jpg|gif)$/,
      use: [{
        loader: 'file-loader',
        options: {
          // name: '[name]_[hash].[ext]' // 按道理是当前项目的hash值.
          // name: '[name]_[chunkhash].[ext]' //Path variable [chunkhash] not implemented in this context: 282-8_[chunkhash].jpg
          name: '[name]_[contenthash].[ext]' // 根据文件的内容,生成的hash
        }
      }]
    }]
  },
  plugins: [
    new CleanWebpackPlugin()
  ]
}